import os
import sys

import django
from django.db.models import F, Q, Avg, Count, Max, Min

sys.path.insert(0, '/Users/mac/PycharmProjects/syl_1912/syl')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'syl.settings')
django.setup()

from books.models import User, Book

user1 = User.objects.get(id=2)
user1.books.add(1)

# 拥有的书, 是一个集合
own_book = user1.books.all()
print(own_book)
# 所有的书, 是一个集合
all_book = Book.objects.all()
print(all_book)
# 所有书-拥有的书
# have_not_book = all_book - own_book
have_not_book = []
for book in all_book:
    if book in own_book:
        pass
    else:
        have_not_book.append(book)
print(have_not_book)
